function Timer(todoFn, tick) {
	var timer;
	var tick = tick;
	var self = this;
	if (!tick) {
		tick = 1000;
	}
	this.beforeStart = function() {
	};
	this.onStop = function() {
		console.log("stop");
	};
	this.stop = function() {
		clearInterval(timer);
		self.onStop();
	};
	this.start = function() {
		self.beforeStart();
		timer = setInterval(todoFn, tick);
	};
}

function CountDownTimer(count, tick) {
	var timer;
	var tick = tick;
	var self = this;
	var defaultCount = count;
	var count = count;
	this.isRunning = false;
	if (!tick) {
		tick = 1000;
	}
	var onTickWrapper = function() {
		count -= 1000;
		self.onTick(count);
		if (count < 0) {
			self.stop();
		}
	}
	this.beforeStart = function() {
		// 可以重写
	};
	this.onStop = function() {
		// 可以重写
		console.log("stop");
	};
	this.stop = function() {
		clearInterval(timer);
		count = defaultCount;
		self.onStop();
		self.isRunning = false;
	};
	this.onTick = function(count) {
		// 可以重写
		console.log(count);
	}
	this.start = function() {
		if (self.isRunning) {
			return;
		}
		self.isRunning = true;
		self.beforeStart();
		timer = setInterval(onTickWrapper, tick);
	};
}
